﻿<UserControl x:Class="MVVM.Views.NumericQuestionView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"      
    xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
    xmlns:prism="http://www.codeplex.com/prism" 
    xmlns:GuidanceTools="clr-namespace:Microsoft.Practices.Prism.GuidanceTools;assembly=Microsoft.Practices.Prism.GuidanceTools" 
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid Margin="5" d:DesignWidth="431" d:DesignHeight="353">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>

        <!-- Feed any binding error into the ViewModel -->
        <i:Interaction.Triggers>
            <ei:PropertyChangedTrigger Binding="{Binding (Validation.HasError), ElementName=textBox}">
                <ei:ChangePropertyAction PropertyName="HasBindingError" TargetObject="{Binding}"
                                         Value="{Binding (Validation.HasError), ElementName=textBox}"/>
            </ei:PropertyChangedTrigger>
        </i:Interaction.Triggers>

        <TextBlock Grid.Column="0" Grid.Row="0" Text="{Binding Question.QuestionText}" Style="{StaticResource QuestionLabelStyle}" />
        <GuidanceTools:InfoTipToggleButton Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left">
            <StackPanel MinWidth="100" MinHeight="24" MaxWidth="400">
                <TextBlock TextWrapping="Wrap"> This is a Numeric Question, a positive integer value is expected.</TextBlock>
                <TextBlock TextWrapping="Wrap"> • To customize the error message shown, the NumericQuestionViewModel validates the format of the input.</TextBlock>
                <TextBlock TextWrapping="Wrap"> • The validation of the maximum number accepted (bussiness logic) is performed by the NumericQuestionModel model.</TextBlock>
                <TextBlock TextWrapping="Wrap"> • The UpdateSourceTrigger="PropertyChanged" is used to update the binding whenever a new character is entered, so the input is validated on every entry.</TextBlock>
            </StackPanel>
        </GuidanceTools:InfoTipToggleButton>
        <TextBox x:Name="textBox" Grid.Column="0" Grid.Row="1" AutomationProperties.AutomationId="NumericQuestionAutomationId">
            <TextBox.Text>
                <Binding Path="Question.Response" 
                         Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" 
                         ValidatesOnExceptions="True"/>
            </TextBox.Text>          
        </TextBox>
    </Grid>
</UserControl>
